package com.funny.wallpaper

import android.content.Context
import android.service.wallpaper.WallpaperService
import android.view.MotionEvent
import android.view.SurfaceHolder

class FunnyWallpaperService : WallpaperService() {
    internal inner class FunnyWallpaperEngine(private val ctx: Context) : Engine() {
        private var surfaceView: FunnySurfaceView? = null
        private fun initView(surfaceHolder: SurfaceHolder) {
            if (surfaceView == null) {
                surfaceView = FunnySurfaceView(ctx)
            }
            surfaceView?.setHolder(surfaceHolder)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onCreate(surfaceHolder0: SurfaceHolder) {
            super.onCreate(surfaceHolder0)
            initView(surfaceHolder0)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onSurfaceChanged(surfaceHolder0: SurfaceHolder, v: Int, v1: Int, v2: Int) {
            super.onSurfaceChanged(surfaceHolder0, v, v1, v2)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onSurfaceCreated(surfaceHolder0: SurfaceHolder) {
            super.onSurfaceCreated(surfaceHolder0)
            surfaceView?.surfaceCreated(surfaceHolder0)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onSurfaceDestroyed(surfaceHolder0: SurfaceHolder) {
            super.onSurfaceDestroyed(surfaceHolder0)
            surfaceView?.surfaceDestroyed(surfaceHolder0)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onTouchEvent(motionEvent0: MotionEvent) {
            super.onTouchEvent(motionEvent0)
            surfaceView?.onTouchEvent(motionEvent0)
        }

        // android.service.wallpaper.WallpaperService$Engine
        override fun onVisibilityChanged(z: Boolean) {
            super.onVisibilityChanged(z)
            surfaceView?.onVisChanged(z)
        }
    }

    override fun onCreateEngine(): Engine {
        FunnyWallpaperHelper.init(applicationContext)
        return FunnyWallpaperEngine(this)
    }
}
